import axios from "axios"
import http from "../utils/request"

//获取验证码
export const getCaptcha = () => http.get("/users/getCaptcha?v=next")

//校验验证码
/**
 * 
 * @param {String} captcha 验证码
 * @returns {Promise}  返回一个promise
 */

export const verifyCaptcha = captcha => http.get("/users/verifyCaptcha", {
    params: {
        captcha
    }
})

//获取手机验证码
export const getSmsCode = phoneNumber => http.post("/sms/send", { phoneNumber })

//手机验证码登入接口
export const smsLogin = code => http.post("users/login?type=sms", { code })

//常规登录
/**
 * 
 * @param {String} username  用户名
 * @param {String} password  密码
 * @returns {Promise}  promise类型
 */
export const login = (username, password) => http.post("users/login", { username, password })

//获取二维码
//get请求，先写地址，再传参，传参要传入对象
export const getQrcode = sid => http.get("/users/getQrcode", { params: { sid } })

//微信登录
export const wechatLogin = wechatCode => http.get("/users/wechatLogin", { params: { wechatCode } })

//用来分页登录的
export const getLoginApi = (componentInstance, page = 1, count = 15) => http.get("/getloginlog", {
    // cancleToken:new CancelToken((c) => {
    //     //c这个方法，可以绑定给组件实例，然后调用此方法可以中断请求
    //     componentInstance.cancleToken = c
    //     console.log(componentInstance);
    // }),
    params: {
        page,
        count
    }
})

//获取学员列表
/**
 * 
 * @param {Number} page 页码
 * @param {Number} count 每页显示的数量
 * @param {String} classes 班级
 * @returns  返回一个promise的方法
 */
export const getStuListApi = (page = 1, count = 15, classes = "") => http.get("/students/getstulist", {
    params: {
        page,
        count,
        class: classes
    }
})
//增加学员信息
export const addStuApi = data => http.post("/students/addstu", data)

//删除学员信息
export const delStuApi = sId => http.get("/students/delstu", { params: { sId } })

//更新学员信息
export const updateStuApi = (sId, token) => http.post("/students/updatestu", { sId, token })

//获取班级
export const getClassApi = () => http.get("/students/getclasses")

//选择班级
//搜索学员
export const searchStuApi = (key = "", count = 10, page = 1) => http.get("/students/searchstu", {
    params: {
        key,
        count,
        page
    }
})